<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
	<div>
		<form id="form1" action="login.json" method="post">
			用户名<b style="color:red">*</b>：<input type="text" name="userName" id="userName" onchange="valideName(this);" value=""><span class="alt" style="display:none;color:red;"></span><br/>
			密码<b style="color:red">*</b>：<input type="password" name="pwd" id="userPwd" value=""><br/>
			确认密码<b style="color:red">*</b>：<input type="password" name="repwd" id="repwd" value=""><br/>
			<input type="button" id="sub" value="注册"><br/>
		</form>
	</div>
<script>
	function valideName(obj){
		obj = $(obj);
		if(undefined==obj.val()||''==obj.val()){
			$('.alt').html('请输入用户名');
            $('.alt').show();
            return ;
		}
		$.ajax({
            type: "POST",
            url: "user/valideUserName",
            data: {
            	userName:obj.val()
            },
            timeout: 1800000,  //30分钟的超时时间
            async: false,
            success: function(opResult){
                if('9000'==opResult.respCode){
                    $('.alt').html(opResult.respMsg);
                    $('.alt').show();
                }else if('0000'==opResult.respCode){
                	$('.alt').html('可以使用');
                    $('.alt').show();
                }
            },
            error:function () {
            	alert('操作失败');
            }
        });
	}
	$(function(){
		$('#sub').click(function(){
			if(undefined==$('#userName').val()||''==$('#userName').val()
					||undefined==$('#userPwd').val()||''==$('#userPwd').val()
					||undefined==$('#repwd').val()||''==$('#repwd').val()
					||$('#repwd').val()!=$('#userPwd').val())
			{
				return ;
			}
			$.ajax({
                type: "POST",
                url: "user/reginer",
                data: {
                	userName:$('#userName').val(),
                	userPwd:$('#userPwd').val()
                },
                timeout: 1800000,  //30分钟的超时时间
                async: false,
                success: function(opResult){
                    if('0000'==opResult.respCode){
                        window.onlocation.href=opResult.obj;
                    } else {
                        alert(opResult.respMsg);
                    }
                },
                error:function () {
                	alert('操作失败');
                }
            });
		})
	})
</script>
</body>
</html>